<?php
/*
	插件概览
*/
global $_RQ,$_AR;
$merchid=$this->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$return=array();
if($_RQ['op']=='edit'){
	$item=pdo_get('jy_supplier_user',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$item['lat_lng']=$item['lat_lng']?json_decode($item['lat_lng'],true):array('lng'=>'');
	$item['onlinetime']=$item['onlinetime']?json_decode($item['onlinetime'],true):array('end'=>'');
	$item['codeimg']=$item['codeimg']?json_decode($item['codeimg'],true):array();
	$item['myshop_tpl']=$item['myshop_tpl']?:0;
	$return['item']=$item;
	$return['status']=array('1'=>'开启','0'=>'关闭');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'商户设置',
		'edit_tab'=>true,
		'edits'=>array(
				array(
					'title'=>'基本信息',
					'list'=>array(
							array('type'=>'string','title'=>'商户名称','name'=>'merchname'),
							array('type'=>'image','title'=>'商户logo','name'=>'logo'),
							array('type'=>'text','title'=>'商户简介','name'=>'desc'),
							array('type'=>'text','title'=>'商户公告','name'=>'remark'),
							array('type'=>'string','title'=>'主营项目','name'=>'salecate'),
							array('name'=>'cateid','title'=>'商户分类','type'=>'select','options'=>'cate','option_title'=>'catename'),
							array('type'=>'string','title'=>'商户联系人','name'=>'realname'),
							array('type'=>'string','title'=>'商户手机','name'=>'mobile'),
							array('type'=>'string','title'=>'商户地址','name'=>'address'),
							array('type'=>'lat_lng','title'=>'商户坐标','name'=>'lat_lng'),
							array('name'=>'offline','title'=>'休息?','type'=>'switch'),
							array('type'=>'time_hour','title'=>'营业时间','name'=>'onlinetime'),
							array('type'=>'image','title'=>'店招','name'=>'topimg'),
							array('name'=>'tel','title'=>'商户电话','type'=>'string'),
							//array('name'=>'mypeisong','title'=>'是否自己配送','type'=>'switch','help'=>'不开启，则由平台配送员统一配送！'),
							//array('type'=>'switch','title'=>'需要制作？','name'=>'ismake','help'=>'开启后，商户有需要制作的过程，制作完成后，后台点发货，配送员才能接单！'),
							//array('name'=>'out_pay','title'=>'配送费','type'=>'string'),
							//array('name'=>'out_price','title'=>'起送金额','type'=>'string'),
							//array('name'=>'man_fee','title'=>'满额免配送费','type'=>'string'),
							//array('name'=>'out_juli','title'=>'最大配送距离','type'=>'unitstring','unit'=>'KM','help'=>'留空则由平台统一'),
							//array('name'=>'out_upfee','title'=>'打包费','type'=>'unitstring','unit'=>'元','help'=>'留空则为0！'),
							array('name'=>'payopenid','title'=>'选择收款人','type'=>'choose_title','action'=>'get_member'),	
							//array('type'=>'switch','title'=>'开启客服','name'=>'iskefu','help'=>'开启客服后，会进入客服界面，没开启，点击拨打客服电话！'),
							//array('type'=>'switch','title'=>'支持分销','name'=>'iscommission','help'=>'支持分销后，别的商户，可以选择添加您的商品到自己的小店，客户购买后享受佣金（佣金比例跟《微客分销》参数保持一致）！'),
							//array('type'=>'string','title'=>'可被复制','name'=>'is_share','help'=>'开启可复制后,他人可以一键复制你的店铺商品,店铺LOGO,描述等！'),
							array('name'=>'codeimg','title'=>'营业执照/许可证','type'=>'images'),
							array('name'=>'content','title'=>'商户详情','type'=>'richtext'),
							
					)
				)
			)
		);
	$return['htmls']=$htmls;
	$return['cate']=pdo_getall('jy_supplier_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	if($_SESSION['os']=='mobile'){
		$return['htmls']=$this->template_url('manage/shop_index');
	}
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['merchname']){
		exi('商户名称必填','error');
	}
	if(!$postdata['lat_lng']){
		exi('请填写坐标！','error');
	}
	if($postdata){
		$data =array(
			'merchname'=>trim($postdata['merchname']),
			'topimg'=>trim($postdata['topimg']),
			'salecate'=>trim($postdata['salecate']),
			'desc'=>$postdata['desc'],
			'remark'=>$postdata['remark'],
			'logo'=>$postdata['logo'],
			'realname'=>trim($postdata['realname']),
			'mobile'=>trim($postdata['mobile']),
			'offline'=>intval($post['offline']),
			'onlinetime'=>ijson_encode($postdata['onlinetime']),
			'lat_lng'=>ijson_encode($postdata['lat_lng']),
			'address'=>trim($postdata['address']),
			'is_share'=>intval($postdata['is_share']),
			'iscommission'=>intval($postdata['iscommission']),
			'iskefu'=>intval($postdata['iskefu']),
			'myshop_tpl'=>intval($postdata['myshop_tpl']),
			'cateid'=>intval($postdata['cateid']),
			'star'=>intval($postdata['star']),
			'sudu'=>intval($postdata['sudu']),
			'isrecommand'=>$postdata['isrecommand'],
			'tel'=>$postdata['tel'],
			'out_pay'=>$postdata['out_pay'],
			'out_price'=>$postdata['out_price'],
			'man_fee'=>$postdata['man_fee'],
			'salenum'=>$postdata['salenum'],
			'groupid'=>$postdata['groupid'],
			'payopenid'=>$postdata['payopenid'],
			'isbrand'=>$postdata['isbrand'],
			'content'=>trim($postdata['content']),
			'mypeisong'=>$postdata['mypeisong'],
			'ismake'=>intval($postdata['ismake']),
			'codeimg'=>ijson_encode($postdata['codeimg']),
			'out_juli'=>$postdata['out_juli'],
			'out_upfee'=>$postdata['out_upfee'],
		);
		$merchid=pdo_getcolumn('jy_supplier_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid),'id');
		if($merchid){
			pdo_update('jy_supplier_user',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['mid']=$_SESSION['uid'];
			$data['applytime']=time();
			pdo_insert('jy_supplier_user',$data);
		}
	}
	exi('设置成功');
}